import java.util.HashSet;
import java.util.Set;


public class Text extends AbstractLeaf
{
	private Set<TextFormatting> formattingStyles = new HashSet<TextFormatting>() ;
	public Text(String value, TextFormatting textFormatting)
	{
		super(value) ;
		if(textFormatting != null)
			formattingStyles.add(textFormatting) ;
	}
	@Override
	public String toDokuWiki()
	{
		StringBuilder stringBuilder = new StringBuilder(value) ;
		for(TextFormatting textFormatting : formattingStyles)
			switch(textFormatting)
			{
				case BOLD :
					stringBuilder.insert(0, "**") ;
					stringBuilder.append("**") ;
					break ;
				case DELETED :
					stringBuilder.insert(0, "<del>") ;
					stringBuilder.append("</del>") ;
					break ;
				case ITALIC :	
					stringBuilder.insert(0, "//") ;
					stringBuilder.append("//") ;
					break ;
				case SUBSCRIPT :
					stringBuilder.insert(0, "<sub>") ;
					stringBuilder.append("</sub>") ;
					break ;
				case SUPERSCRIPT :
					stringBuilder.insert(0, "<sup>") ;
					stringBuilder.append("</sup>") ;
					break ;
				case UNDERLINE :
					stringBuilder.insert(0, "__") ;
					stringBuilder.append("__") ;
					break ;
				case FOOTNOTE :
					stringBuilder.insert(0, "((") ;
					stringBuilder.append("))") ;
					break ;
				case MONOSPACED :
					stringBuilder.insert(0, "<code>") ;
					stringBuilder.append("</code>") ;
					break ;
			}
		return stringBuilder.toString() ;
	}
	@Override
	public String toMediaWiki() 
	{
		return null ;
	}
	@Override
	public String toText2tags() 
	{
		String result = value.replace("\n", "\n\n") ;
		StringBuilder stringBuilder = new StringBuilder(result) ;
		
		for(TextFormatting formatting : formattingStyles)
		{
			switch(formatting)
			{
				case COMMENT :
					stringBuilder.insert(0, "\n%") ;
					stringBuilder.append("\n") ;
					break ;
				case DELETED :
					stringBuilder.insert(0, "--") ;
					stringBuilder.append("--") ;
					break ;
				case UNDERLINE :
					stringBuilder.insert(0, "__") ;
					stringBuilder.append("__") ;
					break ;
				case BOLD :
					stringBuilder.insert(0, "**") ;
					stringBuilder.append("**") ;
					break ;
				case ITALIC :
					stringBuilder.insert(0, "//") ;
					stringBuilder.append("//") ;
					break ;
				case MONOSPACED :
					stringBuilder.insert(0, "``") ;
					stringBuilder.append("``") ;
					break ;
			}
		}
		
		return stringBuilder.toString() ;
	}
}
